#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/15 16:30
# @Author  : afraidbenq
# @File    : logger.py
# @Software: PyCharm
# @Github  : github/afraidbenq
# @Email   : 329189987@qq.com
# @Desc    :
"""
本框架日志模块使用了更优雅的日志记录方案 loguru
https://github.com/Delgan/loguru
"""
import os
from time import strftime

from loguru import logger

from config import settings

# 定义log路径存为文件
logs_path = settings.LOGS_PATH

if not os.path.exists(logs_path):
    os.mkdir(logs_path)

log_path_info = os.path.join(logs_path, f'{strftime("%Y-%m-%d")}_info.log')
log_path_warning = os.path.join(logs_path, f'{strftime("%Y-%m-%d")}_warning.log')
log_path_error = os.path.join(logs_path, f'{strftime("%Y-%m-%d")}_error.log')

# 日志简单配置 文件区分不同级别的日志
logger.add(log_path_info, rotation="500 MB", encoding='utf-8', enqueue=True, level='INFO')
logger.add(log_path_warning, rotation="500 MB", encoding='utf-8', enqueue=True, level='WARNING')
logger.add(log_path_error, rotation="500 MB", encoding='utf-8', enqueue=True, level='ERROR')

__all__ = ["logger"]
